package com.wwp.tbshop.presenter;

import android.util.Log;

import com.wwp.tbshop.model.bean.BaseBean;
import com.wwp.tbshop.model.bean.HomeBean;
import com.wwp.tbshop.view.fragment.HomeFragment;

import java.util.List;

import retrofit2.Call;

import static android.content.ContentValues.TAG;

/**
 * Created by ${wenping} on 6/15/2017.
 */

public class HomeFragmentPresenter extends BasePresenter {

    private HomeFragment mHomeFragment;

    public HomeFragmentPresenter(HomeFragment fragment) {
        this.mHomeFragment = fragment;
    }

    public void loadHomeInfo() {
        //mTakeoutService是在父类中的
        Call<HomeBean> homeCall = mApiService.getHomePic();
        //mCallback 是在父类中的
        homeCall.enqueue(mCallback);
    }

    @Override
    protected void onServerBug(int code) {
        mHomeFragment.onHomeServerBug();
    }

    @Override
    protected void onConnectError(String message) {
        mHomeFragment.onHomeError();
    }

    @Override
    protected void onSuccess(BaseBean baseBean) {
        //解析数据
        HomeBean bean = (HomeBean) baseBean;
        if (bean == null){
            Log.e(TAG, "faild:没有获取到数据"+baseBean.getError_code());
        }else {
            List<HomeBean.HomeTopicBean> homeTopicList = bean.getHomeTopic();
//            Log.e(TAG, "onSuccess" + homeTopicList.size());
            mHomeFragment.onHomeSuccess(homeTopicList);
        }
    }
}